package com.xwj.back.controller;


import com.xwj.back.pojo.FeedBack;
import com.xwj.back.service.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class FeedBackController {

    @Autowired
    private FeedBackService feedBackService;

    @GetMapping("/feedback/all/")
    public List<FeedBack> getAllFeedBack(@RequestParam Map<String,String> data){
        String role = data.get("role");
        String username = data.get("username");
        return feedBackService.getAllFeedBack(role,username);
    }

    @PostMapping("/feedback/delete/")
    public Map<String,String> DeleteFeedBack(@RequestBody Map<String,String> data){
        Integer id = Integer.valueOf(data.get("id"));
        HashMap<String, String> map = new HashMap<>();
        map.put("message", feedBackService.DeleteFeedBack(id));
        return map;
    }

    @PostMapping("/feedback/add/")
    public Map<String,String> addFeedBack(@RequestBody Map<String,String> data){
        Map<String, String> map = new HashMap<>();
        map.put("message", feedBackService.addFeedBack(data));
        return map;
    }

    @GetMapping("/feedback/getById/")
    public Map<String,String> getFeedBackById(@RequestParam Integer id){
        Map<String,String> map = new HashMap<>();
        map.put("content", feedBackService.getFeedBackById(id).getContent());
        map.put("username", feedBackService.getFeedBackById(id).getUsername());
        map.put("avatar", feedBackService.getFeedBackById(id).getAvatar());
        map.put("status", Boolean.toString(feedBackService.getFeedBackById(id).isStatus()));
        return map;
    }

    @PostMapping("/feedback/changeStatus/")
    public Map<String,String> changeStatus(@RequestBody Map<String,String> data){
        Integer id = Integer.valueOf(data.get("id"));
        String role = data.get("role");
        boolean status = Boolean.parseBoolean(data.get("status"));
        HashMap<String, String> map = new HashMap<>();
        map.put("message", feedBackService.changeStatus(id, status, role));
        return map;
    }
    @GetMapping("/feedback/getByStatus")
    public List<FeedBack> getByStatus(@RequestParam Map<String,String> data){
        return feedBackService.getByStatus(data);
    }
}
